package tagger;

import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;

import edu.stanford.nlp.ling.WordTag;
import entity.Tag;
import vn.hus.nlp.tagger.VietnameseMaxentTagger;

public class VietnameseTagger {
	private static VietnameseMaxentTagger helper = new VietnameseMaxentTagger();

	public static void main(String[] html) {

	}

	public static List<Tag> tagFromHtml(String html) {
		List<WordTag> listTag = helper.tagText2(Jsoup.parse(html).text());
		List<Tag> listNoun = new ArrayList<Tag>();
		List<Tag> listAnother = new ArrayList<Tag>();
		String splitted[];
		Tag tag;
		for (int i = 0; i < listTag.size(); i++) {
			String tempString = listTag.get(i).toString();
			splitted = tempString.split("/");
			String title = splitted[0];
			String type = splitted[1];

			// if property noun. ok
			if (type.equalsIgnoreCase("Np")) {
				if (title.length() > 2) {
					tag = new Tag();
					tag.setTitle(title);
					tag.setType(type);
					tag.setAlias(util.StringHelper.replaceVietnamese(title));
					if (!listNoun.contains(tag) && listNoun.size() < 11) {
						listNoun.add(tag);
					}
				}
			} else {
				if (title.length() > 5) {
					tag = new Tag();
					tag.setTitle(title);
					tag.setType(type);
					tag.setAlias(util.StringHelper.replaceVietnamese(title));
					if (!listAnother.contains(tag) && listAnother.size() < 11) {
						listAnother.add(tag);
					}
				}
			}
		}
		listNoun.addAll(listAnother);
		return listNoun;
	}

	public static String tagFromString(String content) {
		List<WordTag> listTag = helper.tagText2(content);
		String splitted[];
		for (int i = 0; i < listTag.size(); i++) {
			String tempString = listTag.get(i).toString();
			splitted = tempString.split("/");
			String title = splitted[0];
			String type = splitted[1];
			System.out.print("Type : " + type);
			System.out.println(" - Length : " + title.length() + " - " + title);

		}
		return "";
	}
}
